var app = getApp();
const wxapi = require('../../utils/wxapi.js');
const util = require('../../utils/util.js');
Page({
  data: {
    statusType: [],
    currentType: 0,
    list: [],
    goodsMap: [],
    logisticsMap: [],
    windowHeight: ''
  },
  onLoad(options) {
    this.getList();
    let systemInfo = wx.getSystemInfoSync()
    this.setData({
      windowHeight: systemInfo.windowHeight,
      currentType: options.id ? options.id : 0
    })
    this.getTypes();
  },
  // 点击tab切换 
  swichNav: function (res) {
    if (this.data.currentType == res.detail.currentNum) return;
    this.setData({
      currentType: res.detail.currentNum
    })
  },
  bindChange: function (e) {
    this.setData({
      currentType: e.detail.current
    })
    if (!this.data.list[e.detail.current].length){}
      // this.getList();   讲道理这里是需要再请求一次数据的
  },
  getList() {
    wx.showLoading();
    setTimeout(wx.hideLoading,1500);
    // wx.hideLoading();
   
  },
  gotoDetail: function (e) {
    let detailId = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: "/pages/other/otherDetail/otherDetail?id=" + detailId
    })
  },
  getTypes(){
    let that = this;
    let key = wx.getStorageSync("secKey");
    wxapi.getTypes(key,5).then(res=>{
      that.setData({
        statusType:res.data
      })
      return res.data;
    }).then((types)=>{
      return types.length && wxapi.getTypesArticles(key,types);
    }).then(rtnData=>{
       console.log(rtnData)
       let colData = rtnData.map(item=>{
         item.data.forEach(i=>{
           i.createtime = util.formatTime(new Date(i.createtime / 1000));
           i.posterUrl = i.posterUrl == "" ? "../../static/image/other-selected.png" : i.posterUrl;
         })
          return item.data;
       })
       that.setData({
         list:colData
       })
    })
  }

})